package com.example.controller;


import com.example.entity.Integral;
import com.example.entity.Merchant;
import com.example.service.IMerchantService;
import com.example.service.impl.IntegralServiceImpl;
import com.example.util.Code;
import com.example.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tyhxzy
 * @since 2023-11-03
 */
@RestController
@RequestMapping("/s/merchant")
public class MerchantController {
    @Autowired
    private IMerchantService iMerchantService;
    @Autowired
    private IntegralServiceImpl integralService;
    //商家选择商店类型
    @PostMapping("/addtype")
    public Result addType(@RequestBody Merchant merchant){
        int i = iMerchantService.addType(merchant);
        if(i>0){
            Integral integral = new Integral();
            integral.setMid(merchant.getZid());
            integralService.addPoints(integral);
            return new Result(Code.SAVE_OK,"注册成功");
        }else {
            return new Result(Code.SAVE_ERR,"注册失败");
        }
    }

    //将状态改为0
    @RequestMapping("/updateStatus/{zid}")
    public Result updateStatus(@PathVariable Integer id){
        int i = iMerchantService.updateStatus(id);
        if (i>0){
            return new Result(Code.UPDATE_OK,"修改成功");
        }else {
            return new Result(Code.UPDATE_ERR,"修改失败");
        }
    }

    //将状态改为1
    @RequestMapping("/updateStatus1/{zid}")
    public Result updateStatus1(@PathVariable Integer id){
        int i = iMerchantService.updateStatus1(id);
        if (i>0){
            return new Result(Code.UPDATE_OK,"修改成功");
        }else {
            return new Result(Code.UPDATE_ERR,"修改失败");
        }
    }
}
